//Accepted
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <iostream>
using namespace std;

int main(){
	//freopen("in.txt", "r", stdin);
	int  i, j, t;
	char s[5][6], a, b;
	
	scanf("%d", &t);
	while(t--){
		for(i=0;i<5;++i)
			scanf("%s", s[i]);
		
		
		a=b=0;
		
		//hori
		for(i=0;i<5;++i)
			for(j=0;j<3;++j){
				if( (s[i][j+2]=='A')&&(s[i][j+1]=='A')&&(s[i][j]=='A')  )a=1;
				if( (s[i][j+2]=='B')&&(s[i][j+1]=='B')&&(s[i][j]=='B')  )b=1;
			}
		//verti
		for(i=0;i<3;++i)
			for(j=0;j<5;++j){
				if( (s[i+2][j]=='A')&&(s[i+1][j]=='A')&&(s[i][j]=='A')  )a=1;
				else if( (s[i+2][j]=='B')&&(s[i+1][j]=='B')&&(s[i][j]=='B')  )b=1;
			}
		//diag
		for(i=0;i<3;++i)
			for(j=0;j<3;++j){
				if( (s[i+2][j+2]=='A')&&(s[i+1][j+1]=='A')&&(s[i][j]=='A')  )a=1;
				else if( (s[i+2][j+2]=='B')&&(s[i+1][j+1]=='B')&&(s[i][j]=='B')  )b=1;
			}
		//DIAG
		for(i=0;i<3;++i)
			for(j=2;j<5;++j){
				if( (s[i+2][j-2]=='A')&&(s[i+1][j-1]=='A')&&(s[i][j]=='A')  )a=1;
				if( (s[i+2][j-2]=='B')&&(s[i+1][j-1]=='B')&&(s[i][j]=='B')  )b=1;
			}
		
		
		if(a==b)printf("draw\n");
		else if(a)printf("A wins\n");
		else printf("B wins\n");
	}
	
	return 0;
}
